package Application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        // 启动Spring应用程序，返回ConfigurableApplicationContext实例
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);

        // 获取Environment对象
        Environment env = context.getEnvironment();

        // 获取并输出server.port属性
        String port = env.getProperty("server.port", "8080"); // 默认值为8080
        System.out.println("应用程序运行在端口: " + port);

        // 获取并输出当前活动的配置文件
        String[] activeProfiles = env.getActiveProfiles();
        System.out.println("当前活动的配置文件: " + String.join(", ", activeProfiles));

        // 获取并输出默认配置文件
        String[] defaultProfiles = env.getDefaultProfiles();
        System.out.println("默认配置文件: " + String.join(", ", defaultProfiles));

        // 关闭上下文
        context.close();
    }
}
